package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Person;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;
import com.hengxinguotong.zhihuichengjian.widget.view.CircleImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2018/10/31
 *
 * 安全培训中人员管理列表适配器
 */

public class PersonManagementAdapter extends RecyclerAdapter<Person, PersonManagementAdapter.PersonManageViewHolder> {

    public PersonManagementAdapter(Context context, List<Person> dataList) {
        super(context, dataList);
    }

    @Override
    public PersonManageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_safety_study, null);
        return new PersonManageViewHolder(view);
    }

    @Override
    public void onBindViewHolder(PersonManageViewHolder holder, int position) {
        holder.bindData(dataList.get(position));
    }

    public class PersonManageViewHolder extends RecyclerAdapter.BaseViewHolder<Person>{
        @BindView(R.id.head_portrait_img)
        CircleImageView headPortraitImg;
        @BindView(R.id.name_tv)
        HXTextView nameTv;
        @BindView(R.id.unit_tv)
        HXTextView unitTv;
        @BindView(R.id.position_tv)
        HXTextView positionTv;
        @BindView(R.id.regist_date_tv)
        HXTextView registDateTv;
        @BindView(R.id.person_detail_tv)
        HXTextView personDetailTv;
        @BindView(R.id.study_detail_tv)
        HXTextView studyDetailTv;
        @BindView(R.id.study_detail_ll)
        LinearLayout studyDetailLl;

        public PersonManageViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(final Person person) {
            Glide.with(context)
                    .load(person.getFileName())
                    .placeholder(R.mipmap.default_head_portrait)
                    .error(R.mipmap.default_head_portrait)
                    .into(headPortraitImg);
            nameTv.setText(person.getPersonName());
            unitTv.setText(person.getUnitName());
            positionTv.setText(person.getCategory());
            registDateTv.setText(person.getEntranceDate());
            studyDetailLl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    clickListener.onClick(person);
                }
            });
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    itemClickListener.onItemClick(person);
                }
            });
        }
    }
}
